﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace game.Blocks
{
    class CHellBlock :  CBaseBlock
    {
       public CHellBlock(World world, Vector2 position,float positiveAngle,float negativeAngle)
            : base(world,position,true)
        {
            fPositiveAngle = (positiveAngle*3.14f) / 180.0f;
            fNegativeAngle = -(negativeAngle*3.14f) / 180.0f;

            _sprite.Body.Rotation = 0;
            _sprite.Body.Friction = 0.2f;
            fCurrentAngle = 0.0f;
            moveToPositive = true;
        }

       public void Draw(SpriteBatch spriteBatch)
        {
            _sprite.Draw(spriteBatch);
        }

      bool moveToPositive;
      const float fAngleMove = 0.5f;

       public override void Update(float fDeltaT)
       {
           if (moveToPositive == true)
           {
               fCurrentAngle += fAngleMove * fDeltaT;

               if (fCurrentAngle >= fPositiveAngle)
               {
                   moveToPositive = false;
               }
               
           }
           else
           {
               fCurrentAngle -= fAngleMove * fDeltaT;

               if (fCurrentAngle <= fNegativeAngle)
               {
                   moveToPositive = true;
               }
           }

           _sprite.Body.Rotation = fCurrentAngle;
       }

       private float fCurrentAngle;
       private float fPositiveAngle;
       private float fNegativeAngle;
    }
}
